<?php
namespace Home\Model;
use Common\Model\BaseModel;

class EquRepairRecordsModel extends BaseModel {

    public $tableName = 'equ_repair_records';

    /**
     * @param $post
     * @return array
     * 更新或修改合同信息
     */
    public function saveEquRepairRecords($data){

        $ret = array('status'=>true,'msg'=>'');
        $post = $this->returnData($data);

        if(!$this->create($post)){

            $ret['status'] = false;
            $ret['msg'] = $this->getError();

        }else{

            
            $res = (null !== $post['equ_repair_records_id']) ? $this->save($post) : $this->add($post);
            
            if(false !== $res){
                $ret['msg'] = '操作成功';
            }else{
                $ret['status'] = false;
                $ret['msg'] = $this->getDbError();
            }
        }

         return $ret;
    }

    public function returnData($post){

        $return = array();

        $return['equ_repair_records_id']  = !empty($post['equ_repair_records_id']) ? intval($post['equ_repair_records_id']) : null;
        $return['repair_record_no']       = !empty($post['repair_record_no']) ? addslashes($post['repair_record_no']) : '';
        $return['user_id']                = !empty($post['user_id']) ? intval($post['user_id']) : '';
        $return['contract_id']            = !empty($post['contract_id']) ? addslashes($post['contract_id']) : '';
        $return['repair_time']            = !empty($post['repair_time']) ? strtotime($post['repair_time']) : time();
        $return['equipment_id']           = !empty($post['equipment_id']) ? intval($post['equipment_id']) : '';
        $return['company_id']             = !empty($post['company_id']) ? intval($post['company_id']) : '';
        $return['comment_id']             = !empty($post['comment_id']) ? intval($post['comment_id']) : '';
        $return['del']                    = 1;
        return $return;
    }

}